package com.denlaku.longan.controller.impl;

import com.denlaku.longan.controller.BaseController;
import com.denlaku.longan.core.Current;
import com.denlaku.longan.core.CurrentInfo;
import com.denlaku.longan.core.RequestContext;
import com.denlaku.longan.http.Resp;
import com.denlaku.longan.http.Return;
import com.denlaku.longan.service.TenantService;
import com.denlaku.longan.vo.Tenant;
import com.denlaku.longan.vo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author tianx
 */
@RestController
public class BaseControllerImpl implements BaseController {
    @Autowired
    private TenantService tenantService;

    @Override
    public Return<CurrentInfo> get() {
        CurrentInfo info = new CurrentInfo();
        RequestContext current = Current.getCurrent();
        User user = current.getUser();
        if (user != null) {
            info.setUserName(user.getName());
        }
        return Resp.success(info);
    }

    @Override
    public Return<List<Tenant>> ownedList() {
        Long userId = Current.getUserId();
        List<Tenant> tenantList = tenantService.ownedList(userId);
        return Resp.success(tenantList);
    }
}
